Platform Explorer / Nuxeo Platform 2023.10

Contribution org.nuxeo.salesforce.automation.contrib--operation

This contribution is part of XML component org.nuxeo.salesforce.automation.contrib inside nuxeo-salesforce-core-2023.0.2.jar /OSGI-INF/automation-contrib.xml

Extension Point

Extension point operation of component AutomationScriptingComponent.

Registration Order

0
The registration order represents the order in which this contribution was registered on its target extention point. This will impact the override/merge behaviour when it is implemented on the target service, and is useful for proper customization of existing contributions.
You can influence this order by adding "require" tags in the containing component declaration, to make sure it is resolved after another component (see "Resolution Order" on components).

Contributed Items

  • <scriptedOperation id="Salesforce.TouchSFLibrary">
          <inputType>document</inputType>
          <outputType>document</outputType>
          <category>javascript</category>
          <param name="update" type="Boolean"/>
          <param name="record" type="Object"/>
          <script>
            <![CDATA[function run(input, params) {
                var sfobject = JSON.parse(params.record);
                var update = params.update;
                var properties = {
                     "dc:title" : sfobject.Name,
                     "sf:objectId" : sfobject.Id,
                     "sf:objectType" : sfobject.sobjectType,
                     "dc:description" : sfobject.Description || '',
                };
                if ('Amount' in sfobject) {
                    properties["sf:objectAmount"] = sfobject.Amount ? sfobject.Amount.toString() : null;
                }
                if (update) {
                    return Document.Update(input, { 'properties': properties });
                } else {
                    var docs = Repository.Query(null, {
                        'query': "SELECT * FROM Document WHERE ecm:isTrashed = 0 AND sf:objectId = '" + sfobject.Id + "' AND ecm:isVersion = 0 AND ecm:mixinType != 'HiddenInNavigation'",
                    });
                    if (docs.length > 0) {
                        return Repository.GetDocument(null, { 'value': docs[0].id });
                    } else {
                        return Document.Create(input, {
                            "type" : "Workspace",
                            "name" : sfobject.Name.replace(/[^A-Za-z0-9_.-]+/g, '-'),
                            "properties" : properties
                        });
                    }
                }
            }]]>
          </script>
        </scriptedOperation>
  • <scriptedOperation id="Salesforce.LinkAsSource">
          <inputType>document</inputType>
          <outputType>document</outputType>
          <category>Salesforce</category>
          <param name="unlink" type="Boolean"/>
          <param name="record" type="Object"/>
          <script>
            <![CDATA[function run(input, params) {
                var sfobject = JSON.parse(params.record);
                Auth.LoginAs(null, {
                	'name': null
                }); // login as sys admin
                var doc = Salesforce.LinkDocument(input, {
                	'unlink': params.unlink,
                	'objectId': sfobject.Id 
                });
                Audit.LogEvent(input, {
                	'event': params.unlink ? 'DocumentUnlinkedFromSalesforceObject' : 'DocumentLinkedToSalesforceObject',
                	'category': 'Salesforce',
                	'comment': sfobject.Name + ' - ' +sfobject.Id 
                })
                return doc;
            }]]>
          </script>
        </scriptedOperation>

XML Source

<extension point="operation" target="org.nuxeo.automation.scripting.internals.AutomationScriptingComponent">
    <scriptedOperation id="Salesforce.TouchSFLibrary">
      <inputType>document</inputType>
      <outputType>document</outputType>
      <category>javascript</category>
      <param name="update" type="Boolean"/>
      <param name="record" type="Object"/>
      <script>
        <![CDATA[function run(input, params) {
            var sfobject = JSON.parse(params.record);
            var update = params.update;
            var properties = {
                 "dc:title" : sfobject.Name,
                 "sf:objectId" : sfobject.Id,
                 "sf:objectType" : sfobject.sobjectType,
                 "dc:description" : sfobject.Description || '',
            };
            if ('Amount' in sfobject) {
                properties["sf:objectAmount"] = sfobject.Amount ? sfobject.Amount.toString() : null;
            }
            if (update) {
                return Document.Update(input, { 'properties': properties });
            } else {
                var docs = Repository.Query(null, {
                    'query': "SELECT * FROM Document WHERE ecm:isTrashed = 0 AND sf:objectId = '" + sfobject.Id + "' AND ecm:isVersion = 0 AND ecm:mixinType != 'HiddenInNavigation'",
                });
                if (docs.length > 0) {
                    return Repository.GetDocument(null, { 'value': docs[0].id });
                } else {
                    return Document.Create(input, {
                        "type" : "Workspace",
                        "name" : sfobject.Name.replace(/[^A-Za-z0-9_.-]+/g, '-'),
                        "properties" : properties
                    });
                }
            }
        }]]>
      </script>
    </scriptedOperation>

    <scriptedOperation id="Salesforce.LinkAsSource">
      <inputType>document</inputType>
      <outputType>document</outputType>
      <category>Salesforce</category>
      <param name="unlink" type="Boolean"/>
      <param name="record" type="Object"/>
      <script>
        <![CDATA[function run(input, params) {
            var sfobject = JSON.parse(params.record);
            Auth.LoginAs(null, {
            	'name': null
            }); // login as sys admin
            var doc = Salesforce.LinkDocument(input, {
            	'unlink': params.unlink,
            	'objectId': sfobject.Id 
            });
            Audit.LogEvent(input, {
            	'event': params.unlink ? 'DocumentUnlinkedFromSalesforceObject' : 'DocumentLinkedToSalesforceObject',
            	'category': 'Salesforce',
            	'comment': sfobject.Name + ' - ' +sfobject.Id 
            })
            return doc;
        }]]>
      </script>
    </scriptedOperation>
    
  </extension>